package com.tjbank.cssys.mybatis.impl;

import com.tjbank.cssys.mybatis.IamRelationshipDao;
import com.tjbank.cssys.mybatis.entity.IamRelationship;
import com.tjbank.cssys.mybatis.entity.IamRelationshipKey;
import com.tjbank.cssys.mybatis.mapper.IamRelationshipMapper;
import com.tjbank.cssys.mybatis.sqlbuilder.IamRelationshipSqlBuilder;
import org.apache.ibatis.exceptions.TooManyResultsException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * IamRelationshipDaoImpl
 * 
 * @author PG(Auto Generator)
 * @version V2.0
 */
@Service
public class IamRelationshipDaoImpl implements IamRelationshipDao {
    @Resource
    private IamRelationshipMapper iamRelationshipMapper;

    public IamRelationshipDaoImpl() {
        super();
    }

    @Override
    public List<IamRelationship> selectListBySqlBuilderWithBLOBs(IamRelationshipSqlBuilder iamRelationshipSqlBuilder) throws RuntimeException {
        return iamRelationshipMapper.selectBySqlBuilderWithBLOBs(iamRelationshipSqlBuilder);
    }

    @Override
    public List<IamRelationship> selectListBySqlBuilder(IamRelationshipSqlBuilder iamRelationshipSqlBuilder) throws RuntimeException {
        return iamRelationshipMapper.selectBySqlBuilder(iamRelationshipSqlBuilder);
    }

    @Override
    public IamRelationship selectBySqlBuilderWithBLOBs(IamRelationshipSqlBuilder iamRelationshipSqlBuilder) throws RuntimeException {
        List<IamRelationship> listIamRelationships = selectListBySqlBuilderWithBLOBs(iamRelationshipSqlBuilder);
        if (listIamRelationships == null || listIamRelationships.isEmpty()) {
            return null;
        } else if (listIamRelationships.size() > 1) {
            throw new TooManyResultsException();
        }
        return listIamRelationships.get(0);
    }

    @Override
    public IamRelationship selectBySqlBuilder(IamRelationshipSqlBuilder iamRelationshipSqlBuilder) throws RuntimeException {
        List<IamRelationship> listIamRelationships = selectListBySqlBuilder(iamRelationshipSqlBuilder);
        if (listIamRelationships == null || listIamRelationships.isEmpty()) {
            return null;
        } else if (listIamRelationships.size() > 1) {
            throw new TooManyResultsException();
        }
        return listIamRelationships.get(0);
    }

    @Override
    public IamRelationship selectByPrimaryKey(IamRelationshipKey iamRelationshipKey) throws RuntimeException {
        return iamRelationshipMapper.selectByPrimaryKey(iamRelationshipKey);
    }

    @Override
    public long countBySqlBuilder(IamRelationshipSqlBuilder iamRelationshipSqlBuilder) throws RuntimeException {
        return iamRelationshipMapper.countBySqlBuilder(iamRelationshipSqlBuilder);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = RuntimeException.class)
    public int insert(IamRelationship iamRelationship) throws RuntimeException {
        return iamRelationshipMapper.insert(iamRelationship);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = RuntimeException.class)
    public int insertUseBatch(List<IamRelationship> listIamRelationships) throws RuntimeException {
        return iamRelationshipMapper.insertUseBatch(listIamRelationships);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = RuntimeException.class)
    public int updateBySqlBuilder(IamRelationship iamRelationship, IamRelationshipSqlBuilder iamRelationshipSqlBuilder) throws RuntimeException {
        iamRelationshipSqlBuilder.setUpdateObject(iamRelationship);
        return iamRelationshipMapper.updateBySqlBuilder(iamRelationshipSqlBuilder);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = RuntimeException.class)
    public int updateBySqlBuilderSelective(IamRelationship iamRelationship, IamRelationshipSqlBuilder iamRelationshipSqlBuilder) throws RuntimeException {
        iamRelationshipSqlBuilder.setUpdateObject(iamRelationship);
        return iamRelationshipMapper.updateBySqlBuilderSelective(iamRelationshipSqlBuilder);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = RuntimeException.class)
    public int updateByPrimaryKey(IamRelationship iamRelationship) throws RuntimeException {
        return iamRelationshipMapper.updateByPrimaryKey(iamRelationship);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = RuntimeException.class)
    public int updateByPrimaryKeySelective(IamRelationship iamRelationship) throws RuntimeException {
        return iamRelationshipMapper.updateByPrimaryKeySelective(iamRelationship);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = RuntimeException.class)
    public int deleteBySqlBuilder(IamRelationshipSqlBuilder iamRelationshipSqlBuilder) throws RuntimeException {
        return iamRelationshipMapper.deleteBySqlBuilder(iamRelationshipSqlBuilder);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = RuntimeException.class)
    public int deleteByPrimaryKey(IamRelationshipKey iamRelationshipKey) throws RuntimeException {
        return iamRelationshipMapper.deleteByPrimaryKey(iamRelationshipKey);
    }
}